package com.ngkj.zmfptback.sys.service;

import com.ngkj.zmfptback.sys.bean.UserEntity;
import com.ngkj.zmfptback.sys.service.read.UserReadService;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

/**
 * @author ChenHN
 * @since 2021/12/1 creation
 **/
@Service
public class UserLoginService implements UserDetailsService {


    @Resource
    private UserReadService userService;

    @Override
    public UserEntity loadUserByUsername(String s) throws UsernameNotFoundException {
        UserEntity userEntity = userService.getUserByUsername(s);
        if (!ObjectUtils.isEmpty(userEntity)){
            return new UserEntity(userEntity.getId(), userEntity.getUsername(), userEntity.getPassword(), AuthorityUtils.createAuthorityList());
        }
        return null;
    }
}
